//
//  MyOrderViewController.m
//  JiongTu
//
//  Created by 杨璟 on 16/3/24.
//  Copyright © 2016年 YSKJ. All rights reserved.
//

#define MYORDER_LOC [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"myOrder.archive"]

#import "MyOrderViewController.h"
#import "FlyFindCarViewController.h"
#import "PublishCarViewController.h"
#import "CheckPassengerViewController.h"

#import "OrderDetailCell.h"
#import "OrderMsgCell.h"

#import "JTButton.h"
#import "JTDriverTrip.h"
#import "JTPassengerTrip.h"
#import "JTOrderTool.h"
#import "JTPushNotification.h"
#import "JTPushTool.h"
#import "JTPayTool.h"
#import "JTUser.h"

#import <AVOSCloud.h>
#import <SVProgressHUD.h>
#import <MJRefresh.h>

@interface MyOrderViewController ()<UITableViewDelegate, UITableViewDataSource, OrderDetailCellDelegate>

/**
 *  『进行中』按钮
 */
@property (weak, nonatomic) IBOutlet JTButton *now;
/**
 *  『已完成』按钮
 */
@property (weak, nonatomic) IBOutlet JTButton *completed;

@property (weak, nonatomic) IBOutlet UITableView *orderTable;

//@property (nonatomic, assign, getter=isOpen) BOOL open;
@property (nonatomic, assign) NSInteger currentClickIndex;
@property (nonatomic, strong) NSIndexPath *currentOpenIndex;

@property (nonatomic, strong) __block NSMutableArray *tripArray;

@property (nonatomic, strong) __block NSMutableArray *passTripArray;
@property (nonatomic, strong) __block NSMutableArray *driverTripArray;

@property (nonatomic, strong)NSMutableArray * endArray;
@property (nonatomic, strong) NSMutableArray * nowDriverTripArray;
@property (nonatomic, strong)NSMutableArray * nowPassengerTripArray;
//@property (nonatomic, assign) int pay;
@end

@implementation MyOrderViewController

static NSString * orderCell = @"orderCell";
static NSString * detailell = @"detailCell";
static NSUInteger orderCellH = 95;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.now.selected = YES;
    self.now.layer.borderWidth = 0.5;
    self.completed.layer.borderWidth = 0.5;
    
    self.now.layer.borderColor = [[UIColor colorWithRed:122/255.0 green:152/255.0 blue:51/255.0 alpha:1.0] CGColor];
    self.completed.layer.borderColor = [[UIColor colorWithRed:122/255.0 green:152/255.0 blue:51/255.0 alpha:1.0] CGColor];
    
    self.navigationItem.title = @"我的订单";
    
    self.currentClickIndex = -1;
    self.currentOpenIndex = [NSIndexPath indexPathForRow:0 inSection:0];
    
    self.orderTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self initialDataSource];
    }];
    [self.orderTable.mj_header beginRefreshing];
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivePayResult:) name:@"JTPayCallBackNotification" object:nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"self.triparray:%ld",self.tripArray.count);
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [SVProgressHUD dismiss];
}

-(void)viewDidAppear:(BOOL)animated
{
    NSLog(@"self.triparray:%ld",self.tripArray.count);
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
/**
 *  查询订单
 */
- (void)initialDataSource {
    
    _endArray =[NSMutableArray array];
    
    NSDate * date =[NSDate date];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat=@"yyyy年MM月dd日";
    NSString *timeStr=[formatter stringFromDate:date];
    //进入时查询本人订单
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, queue, ^{
        if ([JTUser currentUser].isDriver) {
            NSDictionary *dicParameters = @{@"driverId":[AVUser currentUser].objectId,@"date":timeStr};
            [JTOrderTool searchDriverTrip:dicParameters success:^(id responseObject) {
                self.driverTripArray = [JTDriverTrip tripWithAVObjects:responseObject];
                
            } failure:^(NSError *error) {
                [SVProgressHUD showErrorWithStatus:error.localizedDescription];
            }];
            
            AVQuery * query = [AVQuery queryWithClassName:@"Driver"];
            [query whereKey:@"DriverId" equalTo:[AVUser currentUser].objectId];
            AVObject *object = [query getFirstObject];
            AVRelation *relation = [object relationForKey:@"DriverTripInfo"];
            AVQuery *relationQuery = [relation query];
            [relationQuery whereKey:@"Date" greaterThanOrEqualTo:timeStr];
            [relationQuery orderByDescending:@"updatedAt"];
            self.nowDriverTripArray = [JTDriverTrip tripWithAVObjects:[relationQuery findObjects]];
            
            //直接通过司机行程查找自己的订单
//            AVQuery * query = [AVQuery queryWithClassName:@"DriverTrip"];
//            [query whereKey:@"DriverInformation" equalTo:[AVUser currentUser]];
//            [query whereKey:@"Date" greaterThanOrEqualTo:timeStr];
//            [query orderByDescending:@"updatedAt"];
//            self.nowDriverTripArray = [JTDriverTrip tripWithAVObjects:[query findObjects]];
        }
        
    });
    dispatch_group_async(group, queue, ^{
        
        NSDictionary *dicParameters = @{@"passengerId":[AVUser currentUser].objectId,@"date":timeStr};
        [JTOrderTool searchPassengerTrip:dicParameters success:^(id responseObject) {
            self.passTripArray = [JTPassengerTrip tripWithAVObjects:responseObject];
        } failure:^(NSError *error) {
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        }];
        
        AVQuery * query = [AVQuery queryWithClassName:@"PassengerInfo"];
        [query whereKey:@"PassengerId" equalTo:[AVUser currentUser].objectId];
        AVObject *object = [query getFirstObject];
        AVRelation *relation = [object relationForKey:@"PassengerTripInfo"];
        AVQuery *relationQuery = [relation query];
        [relationQuery whereKey:@"Date" greaterThanOrEqualTo:timeStr];
        [relationQuery orderByDescending:@"updatedAt"];
        self.nowPassengerTripArray = [JTPassengerTrip tripWithAVObjects:[relationQuery findObjects]];
        
//        AVQuery * query = [AVQuery queryWithClassName:@"PassengerTrip"];
//        [query whereKey:@"PassengerInformation" equalTo:[AVUser currentUser]];
//        [query whereKey:@"Date" greaterThanOrEqualTo:timeStr];
//        [query orderByDescending:@"updatedAt"];
//        self.nowPassengerTripArray = [JTPassengerTrip tripWithAVObjects:[query findObjects]];
    });
    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
//        [SVProgressHUD dismiss];
        [self.orderTable.mj_header endRefreshing];
//        self.endArray = [self.driverTripArray arrayByAddingObjectsFromArray:self.passTripArray];
        [self.endArray addObjectsFromArray:self.driverTripArray];
        [self.endArray addObjectsFromArray:self.passTripArray];
        
        self.tripArray =[NSMutableArray arrayWithArray:[self.nowDriverTripArray arrayByAddingObjectsFromArray:self.nowPassengerTripArray]];
        [NSKeyedArchiver archiveRootObject:self.tripArray toFile:MYORDER_LOC];
        //处理从通知跳转的情况
        if (self.pushOrder) {
            if ([self.pushOrder.identity isEqualToString:@"乘客"]) {
                NSLog(@"收到来自乘客的通知");
            } else if ([self.pushOrder.identity isEqualToString:@"司机"]) {
                NSLog(@"收到来自司机的通知");
            }
            
        }
    });
}

#pragma mark - 支付完成通知
- (void)receivePayResult:(NSNotification *)notification {
    NSDictionary *resultDict = notification.object;
    
    NSString *resultStatus = resultDict[@"resultStatus"];
    NSLog(@"%@", resultStatus);
    switch ([resultStatus integerValue]) {
        case 6001: {
            [SVProgressHUD showInfoWithStatus:@"您取消了支付"];
        }
            break;
        case 6002: {
            [SVProgressHUD showErrorWithStatus:@"网络连接出错"];
        }
            break;
        case 8000: {
            [SVProgressHUD showInfoWithStatus:@"正在处理中..."];
        }
            break;
        case 4000: {
            [SVProgressHUD showErrorWithStatus:@"订单处理失败"];
        }
            break;
        case 9000: {
            [SVProgressHUD showSuccessWithStatus:@"支付成功!"];
            NSLog(@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"currentClickIndex"]);
            int number =[[[NSUserDefaults standardUserDefaults]objectForKey:@"currentClickIndex"] intValue];
            
            NSLog(@"NUmber Is %d",number);
            
            NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:MYORDER_LOC];
            
//            JTPassengerTrip *locaTrip = [[JTPassengerTrip alloc] init];
//            JTPassengerTrip *tmpTrip = [[JTPassengerTrip alloc] init];
//            if (self.tripArray.count == array.count) {
//                locaTrip = array[number];
//                tmpTrip = self.tripArray[number];
//            }
            
            if ([self compare:self.tripArray WithArray:array]) {
                JTPassengerTrip * passTrip = self.tripArray[number];
                NSLog(@"this is pay :%@", passTrip);
                [AVCloud callFunctionInBackground:@"payForDriver" withParameters:@{@"driverId":passTrip.driver.objectId,@"money":[[NSUserDefaults standardUserDefaults] objectForKey:@"TRIPPRICE"]} block:^(id object, NSError *error) {
                    
//                    NSLog(@"%@",object);
//                    
//                    NSLog(@"ERROR IS ======%@",error);
                }];
                NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
                [dict setObject:[JTUser currentUser].nickname forKey:@"nickName"];
                [dict setObject:[JTUser currentUser].mobilePhoneNumber forKey:@"phoneNumber"];
                [dict setObject:passTrip.start forKey:@"start"];
                [dict setObject:passTrip.end forKey:@"end"];
                [dict setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"TRIPPRICE"] forKey:@"money"];
                
                [AVOSCloud requestSmsCodeWithPhoneNumber:passTrip.driver.mobilePhoneNumber templateName:@"passpassenger" variables:dict callback:^(BOOL succeeded, NSError *error) {
                    if (succeeded) {
                    } else {
                        NSLog(@"%@", error);
                    }
                }];
                
                JTPassengerTrip *payTrip = self.tripArray[number];
                payTrip.isOrdered = @(2);
                AVObject *thisTrip = [AVObject objectWithoutDataWithClassName:@"PassengerTrip" objectId:payTrip.objectId];
                [thisTrip setObject:@(2) forKey:@"IsOrdered"];
                [thisTrip saveInBackground];
                [self.orderTable reloadData];
                
            }
           
        }
            break;
    }
}

- (BOOL)compare:(NSMutableArray *)tmpArray WithArray:(NSArray *)resultArray {
    if (tmpArray.count != resultArray.count) {
        return NO;
    }
    
    for (NSUInteger i = 0; i < resultArray.count; i++) {
        JTPassengerTrip *locaTrip = resultArray[i];
        JTPassengerTrip *tmpTrip = tmpArray[i];
        if (![locaTrip.objectId isEqualToString:tmpTrip.objectId]) {
            return NO;
        }
    }
    
    return YES;
}

#pragma mark -
- (void)setTripArray:(NSMutableArray *)tripArray {
    _tripArray = tripArray;
    
    [self.orderTable reloadData];
}
-(void)setEndArray:(NSMutableArray *)endArray
{
    _endArray = endArray;
    
    [self.orderTable reloadData];
}

- (IBAction)nowClick:(id)sender {
    if (!self.now.isSelected) {
        self.now.selected = !self.now.isSelected;
        self.completed.selected = !self.completed.isSelected;
        [self.orderTable reloadData];
    }
}

- (IBAction)completedClick:(id)sender {
    if (!self.completed.isSelected) {
        self.completed.selected = !self.completed.isSelected;
        self.now.selected = !self.now.isSelected;
        [self.orderTable reloadData];
    }
}



#pragma mark - UITableviewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (self.now.isSelected) {
        return self.tripArray.count;
    }
    else
    {
    return self.endArray.count;
    }
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.now.isSelected) {
        //点击选中的一行
        if (indexPath.row == _currentClickIndex) {
            //展开中
            if (indexPath.row == _currentOpenIndex.row) {
                OrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:detailell];
                cell.trip = self.tripArray[indexPath.row];
                cell.delegate = self;
                cell.indexPath = indexPath;
                return cell;
                //未展开
            } else {
                OrderMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:orderCell];
                cell.trip = self.tripArray[indexPath.row];
                return cell;
            }
            //点击未选中的一行
        } else {
            OrderMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:orderCell];
            cell.trip = self.tripArray[indexPath.row];
            return cell;
        }
    }
    else {
//        if (indexPath.row == _currentClickIndex) {
//            //展开中
//            if (indexPath.row == _currentOpenIndex.row) {
//                OrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:detailell];
//                cell.delegate = self;
//                cell.indexPath = indexPath;
//                cell.trip = self.endArray[indexPath.row];
//                return cell;
//                //未展开
//            } else {
//                OrderMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:orderCell];
//                cell.trip = self.endArray[indexPath.row];
//                return cell;
//            }
//            //点击未选中的一行
//        } else {
            OrderMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:orderCell];
            cell.trip = self.endArray[indexPath.row];
            return cell;
//        }

    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.now.isSelected) {
//        NSLog(@"%d", indexPath.row);
//        if (indexPath.row != self.currentClickIndex) {
//            self.currentClickIndex = indexPath.row;
//            self.currentOpenIndex = indexPath;
//            [tableView reloadRowsAtIndexPaths:@[self.currentOpenIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
//        }
//        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        
        //将索引加到数组中
        NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
        //判断选中不同row状态时候
        if (indexPath.row == self.currentClickIndex) {
            
        } else if (indexPath.row != self.currentClickIndex) {
            indexPaths = [NSArray arrayWithObjects:indexPath,self.currentOpenIndex, nil];
            self.currentOpenIndex = indexPath;
        
        }
        //记下选中的索引
        self.currentClickIndex = indexPath.row;
        
        [[NSUserDefaults standardUserDefaults]setObject:@(indexPath.row) forKey:@"currentClickIndex"];
        
        //刷新
        [tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
        [UIView animateWithDuration:0.25 animations:^{
            tableView.contentOffset = CGPointMake(0, orderCellH * indexPath.row);
        }];

        
    }
    else {
//        if (indexPath.row != _currentClickIndex) {
//            _currentClickIndex = indexPath.row;
//            [tableView reloadRowsAtIndexPaths:@[_currentOpenIndex] withRowAnimation:UITableViewRowAnimationAutomatic];
//            _currentOpenIndex = indexPath;
//        }
//        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//        [UIView animateWithDuration:0.25 animations:^{
//            tableView.contentOffset = CGPointMake(0, orderCellH * indexPath.row);
//        }];
    }
}

//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//    CATransform3D rotation;
//    rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
//    rotation.m34 = 1.0/ -600;
//    
//    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
//    cell.layer.shadowOffset = CGSizeMake(10, 10);
//    cell.alpha = 0;
//    cell.layer.transform = rotation;
//    
//    
//    [UIView animateWithDuration:0.8 animations:^{
//        cell.layer.transform = CATransform3DIdentity;
//        cell.alpha = 1;
//        cell.layer.shadowOffset = CGSizeMake(0, 0);
//    }];
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.now.isSelected) {
        if (indexPath.row == _currentClickIndex) {
            if (indexPath.row == _currentOpenIndex.row) {
                _currentClickIndex = indexPath.row;
                
//                CGFloat height;
//                
//                if (self.tripArray.count == 1) {
//                    height = [UIScreen mainScreen].bounds.size.height - 113;
//                } else if (indexPath.row == self.tripArray.count - 1) {
//                    height = [UIScreen mainScreen].bounds.size.height - 113;
//                } else {
//                    //208为64+48+95+1
//                    height = [UIScreen mainScreen].bounds.size.height - 208;
//                }
//                
//                return height;
                return [UIScreen mainScreen].bounds.size.height - 113;
            }
            return orderCellH;
        }else{
            return orderCellH;
        }
    }
    else {
//        if (indexPath.row == _currentClickIndex) {
//            if (indexPath.row == _currentOpenIndex.row) {
//                _currentClickIndex = indexPath.row;
//                
//                CGFloat height;
//                
//                if (self.tripArray.count == 1) {
//                    height = [UIScreen mainScreen].bounds.size.height - 113;
//                } else if (indexPath.row == self.tripArray.count - 1) {
//                    height = [UIScreen mainScreen].bounds.size.height - 113;
//                } else {
//                    //207为64+48+95+1
//                    height = [UIScreen mainScreen].bounds.size.height - 208;
//                }
//                
//                return height;
//            }
//            return orderCellH;
//        }else{
//            return orderCellH;
//        }
        return orderCellH;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_completed.isSelected ==YES) {
        JTPassengerTrip * pass =_endArray[indexPath.row];
        JTDriverTrip * driver =_endArray[indexPath.row];
        if ([pass.identity isEqualToString:@"乘客"]) {
            NSString * del =[NSString stringWithFormat:@"delete from PassengerTrip where objectId='%@'",pass.objectId];
            [AVQuery doCloudQueryInBackgroundWithCQL:del callback:^(AVCloudQueryResult *result, NSError *error) {
                NSLog(@"%@",error);
            }];
        }
        if ([driver.identity isEqualToString:@"司机"]) {
            NSString * del =[NSString stringWithFormat:@"delete from PassengerTrip where objectId='%@'",driver.objectId];
            [AVQuery doCloudQueryInBackgroundWithCQL:del callback:^(AVCloudQueryResult *result, NSError *error) {
                NSLog(@"11%@",error);
            }];
        }
        [self.endArray removeObjectAtIndex:indexPath.row];
        [_orderTable reloadData];
    }
}
#pragma mark - 行程详情单元格代理
- (void)closeButtonDidClick:(NSIndexPath *)cellIndexPath {
    
    self.currentClickIndex = -1;
    self.currentOpenIndex = [NSIndexPath indexPathForRow:0 inSection:0];
    
    [self.orderTable reloadRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (void)findSamePassengerTrip:(id)trip {
    if ([trip isKindOfClass:[JTPassengerTrip class]]) {
        FlyFindCarViewController *vc = [[FlyFindCarViewController alloc] init];
        vc.sameTrip = trip;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([trip isKindOfClass:[JTDriverTrip class]]) {
        PublishCarViewController *pubVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"pub"];
        pubVC.sameTrip = trip;
        [self.navigationController pushViewController:pubVC animated:YES];
    }
}

- (void)deletePassengerTrip:(id)trip {
    NSString *cql = [NSString string];
    if ([trip isKindOfClass:[JTPassengerTrip class]]) {
        JTPassengerTrip *passengerTrip = trip;
        cql = [NSString stringWithFormat:@"delete from PassengerTrip where objectId='%@'", passengerTrip.objectId];
    } else if ([trip isKindOfClass:[JTDriverTrip class]]) {
        JTDriverTrip *driverTrip = trip;
        cql = [NSString stringWithFormat:@"delete from DriverTrip where objectId='%@'", driverTrip.objectId];
    }

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"真的要删除订单吗？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        [AVQuery doCloudQueryInBackgroundWithCQL:cql callback:^(AVCloudQueryResult *result, NSError *error) {
            if (!error) {
                [SVProgressHUD showSuccessWithStatus:@"成功取消"];
                
                [self closeButtonDidClick:self.currentOpenIndex];
                
                [_tripArray removeObjectAtIndex:self.currentOpenIndex.row];
                
                [self.orderTable reloadData];
                
            } else {
                [SVProgressHUD showErrorWithStatus:error.localizedDescription];
            }
        }];
    }];
    [alert addAction:cancel];
    [alert addAction:sure];
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)payForTrip:(JTPassengerTrip *)trip {
#warning test price 0.01
//    trip.price = @(0.01);
    [SVProgressHUD showWithStatus:@"处理中"];
    AVQuery *query = [AVQuery queryWithClassName:@"PassengerTrip"];
    NSError *error = [NSError errorWithDomain:@"zh_CN" code:0 userInfo:nil];
    AVObject *newestObj = [query getObjectWithId:trip.objectId error:&error];
    NSNumber *isOrdered = [newestObj objectForKey:@"IsOrdered"];
    if (![isOrdered isEqualToNumber:@(1)]) {
        [SVProgressHUD showErrorWithStatus:@"您的订单有误，请刷新后重试"];
    } else {
        [[NSUserDefaults standardUserDefaults]setObject:trip.price forKey:@"TRIPPRICE"];
        
        [JTPayTool pay:trip withBlock:^(NSDictionary *resultDic) {
            [SVProgressHUD dismiss];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"JTPayCallBackNotification" object:resultDic];
        }];
    }
}

- (void)passengerIconClick:(JTPassengerTrip *)passtrip withDriverTrip:(JTDriverTrip *)driverTrip {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    CheckPassengerViewController *vc = [sb instantiateViewControllerWithIdentifier:@"check"];
    vc.onePassenger = passtrip;
    vc.oneDriver = driverTrip;
    vc.refuseBlock = ^(){
        NSMutableArray *mutArr = [driverTrip.passenger mutableCopy];
        for (JTPassengerTrip *eachPass in mutArr) {
            if ([eachPass.objectId isEqualToString:passtrip.objectId]) {
                [mutArr removeObject:eachPass];
            }
        }
        driverTrip.passenger = [mutArr copy];
        [self.orderTable reloadData];
    };
    
    [self presentViewController:vc animated:YES completion:nil];

}

- (void)catchedBtnClick:(JTDriverTrip *)driverTrip {
    
    [JTPushTool pushToRemindPassenger:driverTrip.passenger withBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            [SVProgressHUD showSuccessWithStatus:@"成功通知所有乘客"];
        }
    }];
}

@end
